<!--
Elements show newest of news category have alias $category_alias

Elements params:
- $category_alias	: 	alias of category
-->


<?php 
   if(isset($alias)){
			$new_category = ClassRegistry::init('news.NewsCategory')->find('first', array(
            'conditions'     => array('alias' => $alias),
				'fields'         => array('id', 'alias', 'name'),   
				'contain'	     => array(),
			));
   } else {
		$new_category = ClassRegistry::init('news.NewsCategory')->find('first', array(
			'conditions'     => array('alias <>' => 'root'),
			'fields'         => array('id', 'alias', 'name'),   
			'contain'	     => array(),
		));
		$alias = $new_category['NewsCategory']['alias'];
	}
	
		$popular_places = ClassRegistry::init('news.News')->find('all', array(
			'conditions'	=> array(
				'NewsCategory.alias'	=> $alias,
                'News.is_published'   => 1
			),
			'fields'	=> array('News.id', 'News.alias', 'News.title', 'News.news_date', 'News.description', 'News.image'),
			'contain'	=> array(),
			'limit'		=> 2,
            'order' =>	'News.news_date desc',
			'joins' => array(
				array(
					'table' => 'news_middle',
					'type' => 'INNER',
					'alias' => 'ReferenceCategory',
					'conditions' => array(
						"News.id = ReferenceCategory.page_id"
					)
				),
				array(
					'table' => 'news_categories',
					'type' => 'INNER',
					'alias' => 'NewsCategory',
					'conditions' => array(
						"NewsCategory.id = ReferenceCategory.category_id"
					)
				)
			),
			
		));
		?>

<h3 class="title"><a href="#"><?php echo __('Tin tức');?></a></h3>
<ul class="wd-list-category">
<?php foreach ($popular_places as $item):?>
	<li>
		<a href="<?php echo $html->url(array('plugin' => 'news', 'controller' => 'news', 'action' => 'view', $item['News']['alias'], $alias));?>">
			<img class="img_news" src="<?php if($item['News']['image']) echo $html->url('/files/news/') . $html->getThumbnailName($item['News']['image']); else echo $html->url('/files/news/no-picture.jpg');?>" alt="" />
		</a>
		
		<p><?php echo $this->text->new_truncate(strip_tags($item['News']['description']), 100); ?></p>
	</li>
<?php endforeach;?>
</ul>